﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class mobile_mydiscount : System.Web.UI.Page
{
    protected DataTable result = new DataTable();
    string ind_id;
    protected void Page_Load(object sender, EventArgs e)
    {
        ind_id = this.Request.Params["indid"];
        if (ind_id == null)
        {
            Page.RegisterStartupScript("ss", "<script>alert('登陆出错！')</script>");
            return;//后期添加手机错误转向页面
        }
        else
        {
            if (!IsPostBack)
            {
                try
                {
                    result.Columns.Add("d_title",typeof(string));
                    result.Columns.Add("d_rate",typeof(string));
                    result.Columns.Add("d_type",typeof(string));
                    result.Columns.Add("d_start",typeof(DateTime));
                    result.Columns.Add("d_end",typeof(DateTime));
                    result.Columns.Add("d_rules",typeof(string));
                    result.Columns.Add("d_vip",typeof(string));
                    result.Columns.Add("d_date",typeof(DateTime));
                    result.Columns.Add("d_sn",typeof(string));
                    result.Columns.Add("d_stat",typeof(string));
                    SqlConnection sc1 = new SqlConnection(ConfigurationManager.ConnectionStrings["wbkpt"].ConnectionString.ToString());
                    sc1.Open();
                    SqlCommand get_discount = new SqlCommand();
                    get_discount.Connection = sc1;
                    get_discount.CommandText = "select INFO_DISCOUNT.DISCOUNT_TITLE,INFO_DISCOUNT.DIS_RATE,INFO_DISCOUNT.DISCOUNT_TYPE,INFO_DISCOUNT.DISCOUNT_START,INFO_DISCOUNT.DISCOUNT_END,INFO_DISCOUNT.VIP,INFO_DISCOUNT.RULES,DISCOUNT_ATTEND.ATTEND_DATE,DISCOUNT_ATTEND.SN_CODE,DISCOUNT_ATTEND.STATUS from INFO_DISCOUNT,DISCOUNT_ATTEND where INFO_DISCOUNT.DISCOUNT_ID=DISCOUNT_ATTEND.DISCOUNT_ID and DISCOUNT_ATTEND.IND_ID=@id";
                    get_discount.Parameters.AddWithValue("@id", ind_id);
                    SqlDataReader r = get_discount.ExecuteReader();
                    while (r.Read())
                    {
                       
                        
                        DataRow row = result.NewRow();
                        row["d_title"] = r.GetString(r.GetOrdinal("DISCOUNT_TITLE"));
                        row["d_rate"] = r.GetString(r.GetOrdinal("DIS_RATE"));
                        row["d_start"] = r.GetDateTime(r.GetOrdinal("DISCOUNT_START"));
                        row["d_end"] = r.GetDateTime(r.GetOrdinal("DISCOUNT_END"));
                        row["d_rules"] = r.GetString(r.GetOrdinal("RULES")); 
                        row["d_date"] = r.GetDateTime(r.GetOrdinal("ATTEND_DATE"));
                        row["d_sn"] = r.GetString(r.GetOrdinal("SN_CODE"));
                      
                        if (r.GetString(r.GetOrdinal("DISCOUNT_TYPE")).Equals("CREDIT_EXCHANGE") == true)
                        {
                            row["d_type"] = "积分换折扣<br /><br /> 花费积分/折扣：";
                        }
                        else
                        {
                            row["d_type"] = "积分换返现<br /><br /> 花费积分/返现：";
                        } 
                        if (r.GetInt32(r.GetOrdinal("VIP")) == 1)
                        {
                            row["d_vip"] = "会员独享";
                        }
                        else
                        {
                            row["d_vip"] = "非会员独享";
                        }
                        if (r.GetInt32(r.GetOrdinal("STATUS")) == 1)
                        {
                            row["d_stat"] = "该优惠已被您使用。";
                        }
                        else
                        {
                            row["d_stat"] = "该优惠还未被使用。";
                        }
                        

                        result.Rows.Add(row);
                    }
                    r.Close();

                    DataBind();
                    sc1.Close();
                }
                catch(Exception ss)
                {
                    Page.RegisterStartupScript("ss", "<script>alert('"+ss.Message+ss.StackTrace+"！')</script>");
                    return;
                }
            }
        }
    }
}